extends CharacterBody2D

var canMoving = false
var player
var speed = 1000

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	self.hide()
	self.set_collision_layer_value(5 ,false)

	player = get_tree().get_first_node_in_group("player")
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if canMoving:
		var dir = (player.global_position - global_position).normalized()
		velocity = dir * speed 
		move_and_slide()
	pass

"""
	options.box掉落物父级
	options.ani_name掉落物名称
	options.position掉落物生成坐标
	options.scale掉落物缩放等级
"""
	
func gen_drop_item(options):
	if !options.has("box"):
		options.box = GameMain.duplicate_node
	var ani_temp = self.duplicate()
	#options.box.add_child(ani_temp)
	#ani_temp.show()
	#self.set_collision_layer_value(5 ,true)
	
	options.box.add_child.call_deferred(ani_temp)
	ani_temp.show.call_deferred()
	ani_temp.set_collision_layer_value.call_deferred(5, true)
	
	ani_temp.scale = options.scale if options.has("scale") else Vector2(1,1)
	ani_temp.position = options.position
	ani_temp.get_node("all_animation").play(options.ani_name)
	pass
